package com.lizhk;
import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class ControlFilter implements Filter{

	private FilterConfig myConfig =null;
	public void init(FilterConfig config) throws ServletException{
	this.myConfig = config;	
	}
	public void destroy() {
	this.myConfig = null;
	}
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest httpreq = (HttpServletRequest) request;
		HttpServletResponse  httpres = (HttpServletResponse) response;
		HttpSession session = httpreq.getSession();
		if(null == session.getAttribute("username")){
			ServletContext context = myConfig.getServletContext();
			RequestDispatcher rd = context.getRequestDispatcher("/loginwarn.jsp");
			rd.forward(request, response);
		}
		else {
			chain.doFilter(request, response);
		}
		
	}
	
	}
